import java.util.Comparator;
import java.util.PriorityQueue;

class Person implements Comparable<Person>{
    public int age;
    public String name;

    public Person(int age, String name){
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }
    public int compareTo(Person o) {
        return this.age - o.age;
    }
}
class NameComparator implements Comparator<Person> {
    @Override
    public int compare(Person o1, Person o2) {
        return o1.name.compareTo(o2.name);
    }
}
class Imp implements Comparator<Integer> {
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }
}
public class Text2 {
    public int[] smallestK(int[] arr, int k) {
        int[] tmp = new int[k];
        if(k == 0) {
            return tmp;
        }
        PriorityQueue<Integer> maxHeap = new PriorityQueue<>(new Imp());
        for (int i = 0; i < k; i++) {
            maxHeap.offer(arr[i]);
        }
        for (int i = k; i < arr.length; i++) {
            int es = maxHeap.peek();
            if (arr[i] < es) {
                maxHeap.poll();
                maxHeap.offer(arr[i]);
            }
        }
        for (int i = 0; i < k; i++) {
            tmp[i] = maxHeap.poll();
        }
        return tmp;
    }
    public int[] smallestK1(int[] arr, int k) {
        PriorityQueue<Integer> minHeap = new PriorityQueue<>();
        for (int i = 0; i < arr.length; i++) {
            minHeap.offer(arr[i]);
        }
        int[] tmp = new int[k];
        for (int i = 0; i < k; i++) {
            tmp[i] = minHeap.poll();
        }
        return tmp;
    }
    public static void main3(String[] args) {

    }
    public static void main2(String[] args) {
        Person person1 = new Person(10,"zhangsan");
        Person person2 = new Person(8,"lisi");
        NameComparator nameComparator = new NameComparator();
        PriorityQueue<Person> priorityQueue = new PriorityQueue<>(nameComparator);
        priorityQueue.offer(person1);
        priorityQueue.offer(person2);
    }
    public static void main1(String[] args) {
        Person person1 = new Person(10,"zhangsan");
        Person person2 = new Person(8,"lisi");
        System.out.println(person1.compareTo(person2));//比较大小
        System.out.println(person1.equals(person2));//比较地址
    }
}
